package com.jumi.microservice.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jumi.microservice.common.constant.RequestConstant;
import com.jumi.microservice.constant.ExceptionEnum;
import com.jumi.microservice.domain.Setting;
import com.jumi.microservice.domain.vo.SettingVO;
import com.jumi.microservice.mapper.SettingMapper;
import com.jumi.microservice.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.sql.Wrapper;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> implements SettingService {

    @Autowired
    private SettingMapper settingMapper;


    @Override
    public List<Setting> selectList() {
        List<Setting> list = settingMapper.selectList(null);
        return list;
    }

    @Override
    public void update(SettingVO vo, HttpServletRequest request) {
        Setting setting = settingMapper.selectOne(
                Wrappers.<Setting>lambdaQuery()
                .eq(Setting::getName,vo.getName())
        );
        setting.setMobileMemo(vo.getMobileMemo());
        setting.setMobileTplid(vo.getMobileTplid());
        setting.setMobileSignature(vo.getMobileSignature());
        setting.setModifier(request.getHeader(RequestConstant.ADMIN_NAME));
        settingMapper.update(setting);
    }
}
